/* 添加地址弹窗方法 */
function toAddAddressWinFn() {
    $.colorbox({
        speed: 0,
        inline: true,
        overlayClose: false,
        close: false,
        href: "#addressAdd",
        onOpen: function () {
            $('#js_add_address_form').find('.alert').hide();
        }
    });
}

/* 修改地址弹窗方法 */
function toUpdateAddressWinFn() {
    $.colorbox({
        speed: 0,
        inline: true,
        overlayClose: false,
        close: false,
        href: "#updateAddressForm",
        onOpen: function () {
            $('#js_update_address_form').find('.alert').hide();
        }
    });
}


/*关闭弹窗*/
$(document).on('click', '.js-closewin-btn', function () {
    $.colorbox && $.colorbox.close();
});

/*弹出选择收货地址提醒*/
function selectAddressTip() {
    $.colorbox({
        speed: 0,
        inline: true,
        overlayClose: false,
        close: false,
        href: "#select-address-tip"
    });
}

/*生成订单*/
function createOrder() {
    let shippingId = $(".address-item.active .address-info .address-id").eq(0).text();
    // 没有选择收货地址,弹出提示信息
    if(!shippingId){
        selectAddressTip();
        return false;
    }
    console.log(shippingId);
    let form = new FormData();
    form.append("shippingId",shippingId);
    axios({
        url:"/order/createOrder",
        method:"post",
        data:form
    }).then(function (response) {
        let pattern = /confirm\.html/;
        console.log(response.data);
        // 返回的数据包含confirm.html,进行跳转
        if(pattern.test(response.data)){
            location.href=response.data;
        }else{
            alert(response.data);
        }
    });
    return false;
}
